<?php

class Main extends CI_Controller
{

    public function index ()
    {          
        //$this->post();
        $this->blogs();
    }
 //===============================Neary Post Message=========================================
    public function post(){
        $this->load->view('post');
    }
    public function perform_post(){
    //variable store title and content
      $title = $this->input->post('title');
      $body = $this->input->post('content');
    //do validation
      $this->load->library('form_validation');
      $this->form_validation->set_rules('title', 'Title','required');
      $this->form_validation->set_rules('content', 'Content','required');
      $sucess = $this->form_validation->run();
      if ($sucess) {
          $this->load->model("blog");
          $this->blog->add_post($title,$body);
    //set data to model
      }
      else {
    //$this->display("post");
          $this->post();
      }
    }
    public function do_upload(){
        
    }
//==================================get post from medel and show======================================
    public function blogs(){
  //load model
        $this->load->model('blog');
  //load medel function
        $allmessage = $this->blog->get_post();
  //send to view blogs
        $data = array(
                'messages' => $allmessage
        );
        $this->load->view("blogs",$data);
        
    }
    //Neary Post message
    
    
    
    
    
    private function display ($view, $data = "")
    {
        // check if connected or not using session information
        $connected = $this->session->userdata("current_user") != "";
        // load menu
        $menu_data = array(
                "connected" => $connected);
        $this->load->view('template/menu', $menu_data);
        
        // load content
        if ($data == "") {
            $this->load->view($view);
        }
        else {
            $this->load->view($view, $data);
        }
    }
}

?>